home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / archive / userbox / publicdomain / xfd.lha / xfd / Developper / Sources / XPK.s < prev   
Text File  |  1996-08-03  |  6KB  |  239 lines

  1. *******************************************************
  2. **       XFD external decruncher for XPK files       **
  3. **        written and © 1994 by Georg Hörmann        **
  4. *******************************************************
  5.  
  6.         OUTPUT    "LIBS:xfd/XPK"
  7.  
  8.         SECTION    XPK,CODE
  9.  
  10.         INCDIR    "dh0:Include_Asm"    ;change this as you need it
  11.         INCLUDE    "dh0:xfd/xfdmaster.i"
  12.         INCLUDE "libraries/xpk.i"
  13.  
  14. ; xfdForeman structure MUST be first thing in all external decrunchers
  15.  
  16. F_XPK        moveq    #-1,d0        ;security
  17.         rts
  18.         dc.l    XFDF_ID        ;id
  19.         dc.w    1        ;version
  20.         dc.w    0
  21.         dc.l    0,0        ;private
  22.         dc.l    S_XPKpacked    ;first slave
  23.  
  24.         dc.b    "$VER: XFD XPK decruncher/decryptor by Georg Hörmann",13,10,0
  25. XPKlib        dc.b    "xpkmaster.library",0
  26.         cnop    0,4
  27.  
  28. **************************************************
  29.  
  30. ; xfdSlave structure: this one doesn't support segment decrunching
  31.  
  32. S_XPKpacked    dc.l    S_XPKcrypted    ;next slave
  33.         dc.w    1        ;version
  34.         dc.w    33        ;master version
  35.         dc.l    N_XPKpacked    ;name
  36.         dc.w    XFDPFF_DATA    ;flags
  37.         dc.w    0
  38.         dc.l    RB_XPKpacked    ;recog buffer
  39.         dc.l    DB_XPKpacked    ;decrunch buffer
  40.         dc.l    0        ;recog segment
  41.         dc.l    0        ;decrunch segment
  42.  
  43. N_XPKpacked    dc.b    'XPK Packed',0
  44.         even
  45.  
  46. ;-------------------------------------------------
  47.  
  48. ; Recog buffer function: receives buffer + length in a0/d0
  49.  
  50. RB_XPKpacked    cmp.l    #$24+16,d0    ;min. file length for header and data
  51.         ble.s    .Exit
  52.         cmp.l    #'XPKF',(a0)    ;some more verification
  53.         bne.s    .Exit
  54.         btst    #1,$20(a0)    ;password?
  55.         bne.s    .Exit
  56.         moveq    #1,d0
  57.         rts
  58.  
  59. .Exit        moveq    #0,d0
  60.         rts
  61.  
  62. ;-------------------------------------------------
  63.  
  64. ;Decrunch buffer function: receives bufferinfo in a0
  65.  
  66. DB_XPKpacked    moveq    #0,d0
  67.  
  68. ** combined decrunch/decrypt routine
  69.  
  70. DB_XPK        movem.l    d2-d7/a2-a6,-(a7)
  71.         move.w    d0,d7        ;password flag
  72.         move.l    a0,a5
  73.  
  74. ** open lib
  75.  
  76.         moveq    #0,d0
  77.         lea    XPKlib(pc),a1
  78.         move.l    4.w,a6
  79.         jsr    -552(a6)
  80.         move.w    #XFDERR_MISSINGRESOURCE,xfdbi_Error(a5)
  81.         tst.l    d0
  82.         beq    .Exit
  83.         move.l    d0,a4
  84.  
  85. ** allocate buffer
  86.  
  87.         move.l    xfdbi_SourceBuffer(a5),a2
  88.         move.l    $c(a2),d0
  89.         move.l    d0,xfdbi_TargetBufSaveLen(a5)
  90.         add.l    #XPK_MARGIN,d0
  91.         move.l    d0,xfdbi_TargetBufLen(a5)
  92.  
  93.         move.l    xfdbi_TargetBufMemType(a5),d1
  94.         jsr    -198(a6)
  95.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  96.         move.l    d0,xfdbi_TargetBuffer(a5)
  97.         beq.s    .ExitLib
  98.  
  99. ** decrunch/decrypt
  100.  
  101.         clr.l    -(a7)
  102.         tst.w    d7
  103.         beq.s    .NoPW1
  104.         move.l    xfdbi_Special(a5),-(a7)
  105.         move.l    #XPK_Password,-(a7)
  106. .NoPW1        move.l    xfdbi_TargetBufLen(a5),-(a7)
  107.         move.l    #XPK_OutBufLen,-(a7)
  108.         move.l    d0,-(a7)
  109.         move.l    #XPK_OutBuf,-(a7)
  110.         move.l    xfdbi_SourceBufLen(a5),-(a7)
  111.         move.l    #XPK_InLen,-(a7)
  112.         move.l    a2,-(a7)
  113.         move.l    #XPK_InBuf,-(a7)
  114.         move.l    a7,a0
  115.         move.l    a4,a6
  116.         jsr    _LVOXpkUnpack(a6)
  117.         add.w    #9*4,a7
  118.         tst.w    d7
  119.         beq.s    .NoPW2
  120.         addq.w    #2*4,a7
  121. .NoPW2        tst.l    d0
  122.         beq.s    .Ok
  123.  
  124. ** error -> free buffer
  125.  
  126.         bsr.s    XPKtoXFDerror
  127.         move.w    d0,xfdbi_Error(a5)
  128.  
  129.         move.l    xfdbi_TargetBuffer(a5),a1
  130.         move.l    xfdbi_TargetBufLen(a5),d0
  131.         move.l    4.w,a6
  132.         jsr    -210(a6)
  133.         moveq    #0,d0
  134.         bra.s    .ExitLib
  135.  
  136. ** success
  137.  
  138. .Ok        moveq    #1,d0
  139.  
  140. ** close lib
  141.  
  142. .ExitLib    move.l    d0,-(a7)
  143.         move.l    a4,a1
  144.         move.l    4.w,a6
  145.         jsr    -414(a6)
  146.         move.l    (a7)+,d0
  147.  
  148. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  149.         rts
  150.  
  151. ** some stuff to translate XPK errorcodes to XFD
  152.  
  153. XPKtoXFDerror    cmp.w    #-32,d0
  154.         bge.s    .Ok
  155.         moveq    #-1,d0
  156.         rts
  157. .Ok        not.w    d0
  158.         move.b    .Table(pc,d0.w),d0
  159.         ext.w    d0
  160.         rts
  161.  
  162. .Table        dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOFUNC
  163.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOFILES
  164.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_IOERRIN
  165.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_IOERROUT
  166.         dc.b    XFDERR_CORRUPTEDDATA    ;XPKERR_CHECKSUM
  167.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_VERSION
  168.         dc.b    XFDERR_NOMEMORY        ;XPKERR_NOMEM
  169.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_LIBINUSE
  170.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_WRONGFORM
  171.         dc.b    XFDERR_NOMEMORY        ;XPKERR_SMALLBUF
  172.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_LARGEBUF
  173.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_WRONGMODE
  174.         dc.b    XFDERR_WRONGPASSWORD    ;XPKERR_NEEDPASSWD
  175.         dc.b    XFDERR_CORRUPTEDDATA    ;XPKERR_CORRUPTPKD
  176.         dc.b    XFDERR_MISSINGRESOURCE    ;XPKERR_MISSINGLIB
  177.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_BADPARAMS
  178.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_EXPANSION
  179.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOMETHOD
  180.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_ABORTED
  181.         dc.b    XFDERR_CORRUPTEDDATA    ;XPKERR_TRUNCATED
  182.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_WRONGCPU
  183.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_PACKED
  184.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOTPACKED
  185.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_FILEEXISTS
  186.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_OLDMASTLIB
  187.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_OLDSUBLIB
  188.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOCRYPT
  189.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOINFO
  190.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_LOSSY
  191.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_NOHARDWARE
  192.         dc.b    XFDERR_NOTSUPPORTED    ;XPKERR_BADHARDWARE
  193.         dc.b    XFDERR_WRONGPASSWORD    ;XPKERR_WRONGPW
  194.  
  195.         cnop    0,4
  196.  
  197. **************************************************
  198.  
  199. ; xfdSlave structure: this one doesn't support segment decrunching
  200.  
  201. S_XPKcrypted    dc.l    0        ;no more slaves
  202.         dc.w    1        ;version
  203.         dc.w    33        ;master version
  204.         dc.l    N_XPKcrypted    ;name
  205.         dc.w    XFDPFF_DATA!XFDPFF_PASSWORD    ;flags
  206.         dc.w    0
  207.         dc.l    RB_XPKcrypted    ;recog buffer
  208.         dc.l    DB_XPKcrypted    ;decrunch buffer
  209.         dc.l    0        ;recog segment
  210.         dc.l    0        ;decrunch segment
  211.  
  212. N_XPKcrypted    dc.b    'XPK Crypted',0
  213.         even
  214.  
  215. ;-------------------------------------------------
  216.  
  217. ; Recog buffer function: receives buffer + length in a0/d0
  218.  
  219. RB_XPKcrypted    cmp.l    #$24+16,d0    ;min. file length for header and data
  220.         ble.s    .Exit
  221.         cmp.l    #'XPKF',(a0)    ;some more verification
  222.         bne.s    .Exit
  223.         btst    #1,$20(a0)    ;password?
  224.         beq.s    .Exit
  225.         moveq    #1,d0
  226.         rts
  227.  
  228. .Exit        moveq    #0,d0
  229.         rts
  230.  
  231. ;-------------------------------------------------
  232.  
  233. ;Decrunch buffer function: receives bufferinfo in a0
  234.  
  235. DB_XPKcrypted    moveq    #1,d0
  236.         bra    DB_XPK
  237.  
  238.         END
  239.